package org.ruoyi.interview.controller;

import org.ruoyi.common.web.core.BaseController;
import org.ruoyi.common.core.domain.R;
import org.ruoyi.interview.service.impl.InterviewQuestionDifficultyUpdater;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 面试题难度控制器
 * 提供手动触发难度分析和更新的接口
 */
@RestController
@RequestMapping("/interview/question/difficulty")
public class InterviewQuestionDifficultyController extends BaseController {
    private Logger logger = LoggerFactory.getLogger("UTILLOG");

    @Autowired
    private InterviewQuestionDifficultyUpdater difficultyUpdater;

    /**
     * 手动触发更新所有面试题的难度等级
     *
     * @return 操作结果
     */
    @PostMapping("/updateAll")
    public R<Void> updateAllQuestionDifficulties() {
        try {
            // 异步执行更新任务
            new Thread(() -> {
                try {
                    difficultyUpdater.updateAllQuestionDifficulties();
                } catch (Exception e) {
                    logger.error("更新面试题难度时发生错误", e);
                }
            }).start();

            return R.ok("已开始更新所有面试题的难度等级，请查看日志了解详细进度");
        } catch (Exception e) {
            logger.error("触发更新面试题难度失败", e);
            return R.fail("触发更新失败：" + e.getMessage());
        }
    }
}
